using System;
using System.ComponentModel;

namespace CosyTrade.Data
{
    [Serializable]
    public abstract class BusinessBase : UndoableBase, IEditableObject
    {
        [NonSerialized] protected bool IsBindingStatus = false;

        #region IEditableObject Members

        public void BeginEdit()
        {
            if (!IsBindingStatus)
            {
                IUndoable undoable = this;
                undoable.CopyState();
                IsBindingStatus = true;
            }
        }

        public void EndEdit()
        {
            if (IsBindingStatus)
            {
                IBusiness undoable = this;
                undoable.AffrimChanges();
                IsBindingStatus = false;
            }
        }

        public void CancelEdit()
        {
            if (IsBindingStatus)
            {
                IUndoable undoable = this;
                undoable.UndoChanges();
                IsBindingStatus = false;
            }
        }

        #endregion
    }
}